import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author wcj
 * @Date 2021/6/9 14:58
 * @Version 1.0
 */
public class ConditionUseCase {

    Lock lock = new ReentrantLock();
    private Condition condition = lock.newCondition();

    /**
     * Condition也可以用于实现等待通知机制，但是必须由Lock对象new一个Condition
     *
     * @throws InterruptedException
     */
    public void conditionWait() throws InterruptedException {
        lock.lock();
        try {
            condition.await();
        } finally {
            lock.unlock();
        }
    }

    public void conditionSignal() {
        lock.lock();
        try {
            condition.signal();
        } finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) {

    }
}
